class Solution(object):
    def reconstructMatrix(self, upper, lower, colsum):
        if upper + lower != sum(colsum):
            return []
        c_num = colsum.count(2)
        if c_num > min(upper, lower):
            return []
        f_num = upper - c_num
        n = len(colsum)
        out = [[0 for _ in range(n)] for _ in range(2)]
        for index, num in enumerate(colsum):
            if num == 2:
                out[0][index] = 1
                out[1][index] = 1
            if num == 1:
                if f_num > 0:
                    out[0][index] = 1
                    f_num -= 1
                else:
                    out[1][index] = 1
        return out
